106

Beginner’s Guide to Code Algorithms

106

STEP 2 continued

Selection.ClearContents

Cells(1, 1) =​ “From”

Cells(1, 2) =​ “To”

Cells(1, 3) =​ “Additional Connection Name”

CurrentSheet.Select

Range(“D:D”).Select

Selection.ClearContents

Sheets(“Entities”).Select

RowsCompletedForCurrentMax =​ 0

Call FindMax(arow, MaxCount)

Call FindRowToGraph(RowToGraph, ia, arow)

Previousarow =​ arow

HighestMaxCount =​ Worksheets(“Entities”).Cells(arow, 3).Value

ToggleSwitch =​ -​1

PreviousToggleSwitch =​ ToggleSwitch

MaxNextLeftShape =​ 1

MaxNextRightSHape =​ 1

STEP 2 functions

Sub FindMax(arow As Integer, MaxCount As Integer)

     

      Set rng =​ Sheets(“Entities”).Range(Cells(2, 4), Cells(NumberOfEntities, 4))

      MaxCount =​ Application.WorksheetFunction.Max(rng)

      Set WorkRange =​ rng.Find(what:=​MaxCount)

      arow =​ WorkRange.Row

      Worksheets(“Entities”).Cells(arow, 4).Value =​ 0

End Sub

Sub FindRowToGraph(RowToGraph As Integer, ia As Integer, arow As Integer)

      RowToGraph =​ 0

     

      For ia =​ 1 To NumberOfRows

       

        If Worksheets(“Entities”).Cells(arow, 1) =​ Sheets(CurrentSheetName).

Cells(ia, 2) And Sheets(CurrentSheetName).Cells(ia, 4) <> “Y” Then

        RowToGraph =​ ia

        ToggleSwitch =​ -​1

        Sheets(CurrentSheetName).Cells(ia, 4) =​ “Y”

        Exit For

      End If

    Next

    If RowToGraph =​ 0 Then

      For ia =​ 1 To NumberOfRows

        If Worksheets(“Entities”).Cells(arow, 1) =​ Sheets(CurrentSheetName).

Cells(ia, 1) And Sheets(CurrentSheetName).Cells(ia, 4) <> “Y” Then

          RowToGraph =​ ia

          ToggleSwitch =​ 1

          Sheets(CurrentSheetName).Cells(ia, 4) =​ “Y”

          Exit For

        End If

      Next

    End If

End Sub